<?php
namespace app\api\controller\user;

use app\api\controller\Controller;
use app\api\model\user\PointsLog as PointsLogModel;
/**
 * 用户分享控制器
 * Class Share
 * @package app\api\controller\user
 */
class Share extends Controller
{
    /* @var \app\api\model\User $user */
    private $user;


    /**
     * 构造方法
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function _initialize()
    {
        parent::_initialize();
        // 用户信息
        $this->user = $this->getUser();
    }

    /**
     * 用户分享平台
     * @return array
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function share()
    {
        $model = new PointsLogModel;
        if ($model->userShare($this->user['user_id'])) {
            return $this->renderSuccess([],'分享成功');
        }
        return $this->renderError($model->getError() ?: '分享失败');
    }

}